/**
 * <p>Copyright (c) 2011 深圳市鹏途信息技术有限公司 </p>
 * <p>				   All right reserved. 		     </p>
 *
 * <p>项目名称 ： 	东莞交通工程质量监督综合业务系统        </p>
 * <p>创建者   :	libitum
 *
 * <p>描   述  :   ConveyAction.java for com.pengtu.web.admin    </p>
 *
 * <p>最后修改 : $: 2011-7-23-下午05:33:06 v 1.0.0	 libitum   $     </p>
 *
 */

package com.pengtu.web.admin;

import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.pengtu.Constants;
import com.pengtu.dao.Page;
import com.pengtu.dao.QueryFilter;
import com.pengtu.entity.admin.Convey;
import com.pengtu.entity.app.Attachment;
import com.pengtu.entity.app.User;
import com.pengtu.entity.history.HistoryProject;
import com.pengtu.security.SpringSecurityUtils;
import com.pengtu.service.FProjectManager;
import com.pengtu.service.NumberManager;
import com.pengtu.service.admin.ConveyaManager;
import com.pengtu.service.app.SystemManager;
import com.pengtu.service.history.HistoryProjectManager;
import com.pengtu.utils.DateUtils;
import com.pengtu.utils.web.ControlHelpUtil;
import com.pengtu.utils.web.Struts2Utils;
import com.pengtu.web.BaseActionSupport;

/**
 * 
 * ConveyAction
 * 
 * 2011-7-23 下午05:33:06
 * 
 * @version 1.0.0
 * 
 */
@Results({
		@Result(name = Constants.START, location = "${ctx}/admin/convey!submit.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = Constants.END, location = "${ctx}/admin/convey!info.action", type = "redirect"),
		@Result(name = Constants.OVER, location = "${ctx}/admin/convey!info.action", type = "redirect"),
		@Result(name = "part", location = "${ctx}/admin/convey!judge.action?id=${id}", type = "redirect"),
		@Result(name = "part0", location = "${ctx}/admin/convey!login.action?id=${id}", type = "redirect"),
		@Result(name = "part1", location = "${ctx}/admin/convey!view.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part2", location = "${ctx}/admin/convey!page.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part3", location = "${ctx}/admin/convey!issue.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part4", location = "${ctx}/admin/convey!letter.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part5", location = "${ctx}/admin/convey!look.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part6", location = "${ctx}/admin/convey!leader.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part7", location = "${ctx}/admin/convey!sixth.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part8", location = "${ctx}/admin/convey!eight.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part9", location = "${ctx}/admin/convey!nine.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part10", location = "${ctx}/admin/convey!tenth.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = "part11", location = "${ctx}/admin/convey!eleven.action?id=${id}&taskid=${taskid}", type = "redirect"),
		@Result(name = Constants.LAST, location = "${ctx}/admin/convey!taketask.action?id=${id}&taskid=${taskid}&status=${status}", type = "redirect"),
		@Result(name = Constants.OWN, location = "${ctx}/admin/convey/history.action?key=${id}&pngFileName=convey.png&acc=1-0", type = "redirect"),
		@Result(name = Constants.DONE, location = "${ctx}/admin/convey/history.action?key=${id}&pngFileName=oconvey.png&acc=1-0", type = "redirect") })
public class ConveyAction extends BaseActionSupport<Convey> {

	/**
	 * serialVersionUID:TODO
	 * 
	 * @since 1.0.0
	 */

	private static final long serialVersionUID = 1L;

	private String id;
	private Convey entity;
	private String taskid;
	private Page<Convey> page = new Page<Convey>(10);
	private List<File> upload;
	private List<String> uploadFileName;
	private List<String> uploadContentType;
	private String status;
	private User user = SpringSecurityUtils.getCurrentUser();

	private ConveyaManager conveyaManager;
	private SystemManager systemManager;
	private FProjectManager fProjectManager;
	private NumberManager numberManager;


	private HistoryProjectManager historyProjectManager;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTaskid() {
		return taskid;
	}

	public void setTaskid(String taskid) {
		this.taskid = taskid;
	}

	public Page<Convey> getPage() {
		return page;
	}

	public void setPage(Page<Convey> page) {
		this.page = page;
	}

	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 * uploadFile
	 * 
	 * @return the uploadFile
	 * @since 1.0.0
	 */

	public List<File> getUpload() {
		return upload;
	}

	/**
	 * @param uploadFile
	 *            the uploadFile to set
	 */
	public void setUpload(List<File> upload) {
		this.upload = upload;
	}

	/**
	 * uploadFileName
	 * 
	 * @return the uploadFileName
	 * @since 1.0.0
	 */

	public List<String> getUploadFileName() {
		return uploadFileName;
	}

	/**
	 * @param uploadFileName
	 *            the uploadFileName to set
	 */
	public void setUploadFileName(List<String> uploadFileName) {
		this.uploadFileName = uploadFileName;
	}

	/**
	 * uploadContentType
	 * 
	 * @return the uploadContentType
	 * @since 1.0.0
	 */

	public List<String> getUploadContentType() {
		return uploadContentType;
	}

	/**
	 * @param uploadContentType
	 *            the uploadContentType to set
	 */
	public void setUploadContentType(List<String> uploadContentType) {
		this.uploadContentType = uploadContentType;
	}

	@Autowired
	public void setNumberManager(NumberManager numberManager) {
		this.numberManager = numberManager;
	}
	
	@Autowired
	public void setConveyaManager(ConveyaManager conveyaManager) {
		this.conveyaManager = conveyaManager;
	}

	@Autowired
	public void setSystemManager(SystemManager systemManager) {
		this.systemManager = systemManager;
	}

	@Autowired
	public void setfProjectManager(FProjectManager fProjectManager) {
		this.fProjectManager = fProjectManager;
	}

	@Autowired
	public void setHistoryProjectManager(
			HistoryProjectManager historyProjectManager) {
		this.historyProjectManager = historyProjectManager;
	}

	public Convey getModel() {
		return entity;
	}

	public String list() throws Exception {
		List<Convey> conveys = conveyaManager.find(user);
		List<Convey> conveyList = new ArrayList<Convey>();
		if (StringUtils.isEmpty(status)) {
			conveyList = conveys;
		} else {
			for (Convey convey : conveys) {
				if (convey.getStatus().equals(status)) {
					conveyList.add(convey);
				}
			}
		}
		ControlHelpUtil.setObjectToRequest("conveys", conveyList);
		return SUCCESS;
	}

	/**
	 * 所有发文管理 info: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String info() throws Exception {
		QueryFilter queryfilter = QueryFilter.buildFromHttpRequest(Struts2Utils
				.getRequest());
		if (!page.isOrderBySetted()) {
			page.setOrderBy("createDate");
			page.setOrder(Page.DESC);
		}
		page = conveyaManager.findPage(page, queryfilter);
		return Constants.INFO;
	}

	public String input() throws Exception {
		Struts2Utils.getRequest().setAttribute("cFlag",
				Struts2Utils.getParameter("cFlag"));
		return INPUT;
	}

	/**
	 * 判断发文字号是否唯一 checkNum: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String checkNum() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String newNum = request.getParameter("num");
		String oldNum = request.getParameter("oldNum");
		if (conveyaManager.isNumUnique(newNum, oldNum)) {
			Struts2Utils.renderText("true");
		} else {
			Struts2Utils.renderText("false");
		}
		return null;
	}

	/**
	 * 判断标题是否唯一 checkTitle: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String checkTitle() throws Exception {
		HttpServletRequest request = ServletActionContext.getRequest();
		String newTitle = request.getParameter("title");
		String oldTitle = request.getParameter("oldTitle");
		if (conveyaManager.isTitleUnique(newTitle, oldTitle)) {
			Struts2Utils.renderText("true");
		} else {
			Struts2Utils.renderText("false");
		}
		return null;
	}

	/**
	 * 查看发文内容 png: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String png() throws Exception {
		Struts2Utils.getRequest().setAttribute("flag",
				Struts2Utils.getParameter("flag"));
		return Constants.PNG;
	}

	public void preparePng() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	public String second() throws Exception {
		String letter = Struts2Utils.getParameter("letter");
		if (StringUtils.isEmpty(entity.getDraft())) {
			entity.setDraft(user.getUserName());
		}
		List<Convey> conveys = conveyaManager.get();
		if (StringUtils.isEmpty(entity.getNum())) {
			String number = numberManager.getRandomNum();
			for (Convey convey : conveys) {
				if (StringUtils.isNotEmpty(convey.getNum())) {
					String str = convey.getNum().substring(10, 12);
					if (StringUtils.equals(str, number)) {
						number = numberManager.getRandomNum();
					}
				}
			}
			int date = DateUtils.getCurrentYear();
			String str = "东交监" + letter + "[" + date + "]" + number + "号";
			entity.setNum(str);
		}
		if (StringUtils.isEmpty(entity.getStatus())) {
			entity.setStatus("01");
		}
		if (StringUtils.isEmpty(entity.getFlag())) {
			entity.setFlag("0");
		}
		entity.setSentOrgName(user.getOrgName());
		entity.setDraftDate(new Date());
		conveyaManager.save(entity);
		String rootPath = Struts2Utils.getAppRootPath();
		if (null != upload) {
			for (int i = 0; i < upload.size(); i++) {
				Attachment attachmention = new Attachment();
				entity.setAcctPetitionFile(uploadFileName.get(i));
				attachmention.setUpfile(upload.get(i));
				attachmention.setUpfileFileName(uploadFileName.get(i));
				attachmention.setType(uploadContentType.get(i));
				attachmention.setTableId(entity.getId());
				attachmention.setTableField("conveyFile");
				attachmention.setTableName("convey");
				attachmention.setFileTime(new Date());
				attachmention.setPartName(user.getUserName());

				if (StringUtils.equals(entity.getStatus(), "01")) {
					attachmention.setType("收文拟稿");
				} else if (StringUtils.equals(entity.getStatus(), "02")) {
					attachmention.setType("审核修改");
				} else if (StringUtils.equals(entity.getStatus(), "03")) {
					attachmention.setType("拟办修改");
				}

				systemManager.uploadFile(rootPath, attachmention);
			}
		}
		return "part0";
	}

	public void prepareSecond() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 启动流程 start: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String start() throws Exception {
		String usernames = Struts2Utils.getParameter("usernames");
		String deploymentId = fProjectManager.getByKey("convey")
				.getDeploymentId();
		String key = Struts2Utils.getParameter("key");
		String value = Struts2Utils.getParameter("value");
		String key1 = Struts2Utils.getParameter("key1");
		String value1 = Struts2Utils.getParameter("value1");
		Map<String, Object> variables = new HashMap<String, Object>();
		if (StringUtils.isNotEmpty(key)) {
			variables.put(key, value);
		}
		if (StringUtils.isNotEmpty(key1)) {
			variables.put(key1, value1);
		}
		if (StringUtils.isNotEmpty(usernames)) {
			variables.put("usernames", usernames);
		}
		conveyaManager.start(entity, deploymentId, user, "convey", variables);
		return Constants.OVER;
	}

	public void prepareStart() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	public String save() throws Exception {
		String letter = Struts2Utils.getParameter("letter");
		if (StringUtils.isEmpty(entity.getDraft())) {
			entity.setDraft(user.getUserName());
		}
		List<Convey> conveys = conveyaManager.get();
		if (StringUtils.isEmpty(entity.getNum())) {
			String number = numberManager.getRandomNum();
			for (Convey convey : conveys) {
				if (StringUtils.isNotEmpty(convey.getNum())) {
					String str = convey.getNum().substring(10, 12);
					if (StringUtils.equals(str, number)) {
						number = numberManager.getRandomNum();
					}
				}
			}
			int date = DateUtils.getCurrentYear();
			String str = "东交监" + letter + "[" + date + "]" + number + "号";
			entity.setNum(str);
		}
		if (StringUtils.isEmpty(entity.getStatus())) {
			entity.setStatus("01");
		}
		if (StringUtils.isEmpty(entity.getFlag())) {
			entity.setFlag("0");
		}
		entity.setSentOrgName(user.getOrgName());
		entity.setDraftDate(new Date());
		conveyaManager.save(entity);
		String rootPath = Struts2Utils.getAppRootPath();
		if (null != upload) {
			for (int i = 0; i < upload.size(); i++) {
				Attachment attachmention = new Attachment();
				entity.setAcctPetitionFile(uploadFileName.get(i));
				attachmention.setUpfile(upload.get(i));
				attachmention.setUpfileFileName(uploadFileName.get(i));
				attachmention.setType(uploadContentType.get(i));
				attachmention.setTableId(entity.getId());
				attachmention.setTableField("conveyFile");
				attachmention.setTableName("convey");
				attachmention.setFileTime(new Date());
				attachmention.setPartName(user.getUserName());

				if (StringUtils.equals(entity.getStatus(), "01")) {
					attachmention.setType("收文拟稿");
				} else if (StringUtils.equals(entity.getStatus(), "02")) {
					attachmention.setType("审核修改");
				} else if (StringUtils.equals(entity.getStatus(), "03")) {
					attachmention.setType("拟办修改");
				}

				systemManager.uploadFile(rootPath, attachmention);
			}
		}
		return Constants.END;
	}
	
	/**
	 * 保存
	 * save2:
	 * 适用:
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	public String save2() throws Exception {
		String letter = Struts2Utils.getParameter("letter");
		if (StringUtils.isEmpty(entity.getDraft())) {
			entity.setDraft(user.getUserName());
		}
		List<Convey> conveys = conveyaManager.get();
		if (StringUtils.isEmpty(entity.getNum())) {
			String number = numberManager.getRandomNum();
			for (Convey convey : conveys) {
				if (StringUtils.isNotEmpty(convey.getNum())) {
					String str = convey.getNum().substring(10, 12);
					if (StringUtils.equals(str, number)) {
						number = numberManager.getRandomNum();
					}
				}
			}
			int date = DateUtils.getCurrentYear();
			String str = "东交监" + letter + "[" + date + "]" + number + "号";
			entity.setNum(str);
		}
		if (StringUtils.isEmpty(entity.getStatus())) {
			entity.setStatus("01");
		}
		if (StringUtils.isEmpty(entity.getFlag())) {
			entity.setFlag("0");
		}
		entity.setSentOrgName(user.getOrgName());
		entity.setDraftDate(new Date());
		conveyaManager.save(entity);
		String rootPath = Struts2Utils.getAppRootPath();
		if (null != upload) {
			for (int i = 0; i < upload.size(); i++) {
				Attachment attachmention = new Attachment();
				entity.setAcctPetitionFile(uploadFileName.get(i));
				attachmention.setUpfile(upload.get(i));
				attachmention.setUpfileFileName(uploadFileName.get(i));
				attachmention.setType(uploadContentType.get(i));
				attachmention.setTableId(entity.getId());
				attachmention.setTableField("conveyFile");
				attachmention.setTableName("convey");
				attachmention.setFileTime(new Date());
				attachmention.setPartName(user.getUserName());

				if (StringUtils.equals(entity.getStatus(), "01")) {
					attachmention.setType("收文拟稿");
				} else if (StringUtils.equals(entity.getStatus(), "02")) {
					attachmention.setType("审核修改");
				} else if (StringUtils.equals(entity.getStatus(), "03")) {
					attachmention.setType("拟办修改");
				}

				systemManager.uploadFile(rootPath, attachmention);
			}
		}
		return "part";
	}
	
	public void prepareSave2() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 指定拟办人员 login: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String login() throws Exception {
		return LOGIN;
	}

	public void prepareLogin() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	public String assign() throws Exception {
		return Constants.ASSIGN;
	}

	public void prepareAssign() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 负责人审核查看页面 view: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String view() throws Exception {
		return VIEW;
	}

	public void prepareView() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 审核提交 save1: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String save1() throws Exception {
		String outcome = Struts2Utils.getParameter("outcome");
		String view = Struts2Utils.getParameter("view");
		String key = Struts2Utils.getParameter("key");
		String value = Struts2Utils.getParameter("value");
		String key1 = Struts2Utils.getParameter("key1");
		String value1 = Struts2Utils.getParameter("value1");
		String count = Struts2Utils.getParameter("count");
		String leader = Struts2Utils.getParameter("leader");
		Map<String, Object> variables = new HashMap<String, Object>();
		HistoryProject historyProject = historyProjectManager.get(taskid);
		System.out.println("++"+taskid);
		System.out.println("---"+historyProject);
		historyProject.setEndDate(new Date());
		historyProject.setMessage(user.getName() + "：" + view);
		if (StringUtils.isNotEmpty(key)) {
			variables.put(key, value);
		}
		if (StringUtils.isNotEmpty(key1)) {
			variables.put(key1, value1);
		}
		if (StringUtils.isNotEmpty(count)) {
			variables.put("count", count);
		}
		if (StringUtils.isNotEmpty(leader)) {
			variables.put("leader", leader);
		}
		conveyaManager.completeTask(taskid, outcome, variables);
		conveyaManager.save(entity);
		historyProjectManager.save(historyProject);
		return Constants.OVER;
	}

	public void prepareSave1() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 删除
	 */
	public String delete() throws Exception {
		conveyaManager.delete(entity);
		addActionMessage("删除成功！");
		return Constants.END;
	}

	public void prepareDelete() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 复核页面 page: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String page() throws Exception {
		return Constants.PAGE;
	}

	public void preparePage() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 部门会签页面 issue: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String issue() throws Exception {
		return Constants.ISSUE;
	}

	public void prepareIssue() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 资信室查看 letter: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String letter() throws Exception {
		return Constants.LETTER;
	}

	public void prepareLetter() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 发文页面 look: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String look() throws Exception {
		return Constants.LOOK;
	}

	public void prepareLook() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 发文页面 leader: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String leader() throws Exception {
		return Constants.LEADER;
	}

	public void prepareLeader() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 归档 sixth: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String sixth() throws Exception {
		return "sixth";
	}

	public void prepareSixth() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 办公室审核 eight: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String eight() throws Exception {
		return "eight";
	}

	public void prepareEight() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 资信室查看 nine: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String nine() throws Exception {
		return "nine";
	}

	public void prepareNine() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 发文 tenth: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String tenth() throws Exception {
		return "tenth";
	}

	public void prepareTenth() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}
	
	/**
	 * 部门负责人处理
	 * eleven:
	 * 适用:
	 * @return
	 * @throws Exception 
	 * @exception 
	 * @since  1.0.0
	 */
	public String eleven() throws Exception {
		return "eleven";
	}

	public void prepareEleven() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 从业务到流程处理接口 judge: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String judge() throws Exception {
		taskid = conveyaManager.isPersonalTasks(user, id);
		if (StringUtils.isEmpty(status)) {
			status = ControlHelpUtil.getStatus();
		}
		if (StringUtils.isNotEmpty(taskid)) {
			return Constants.LAST;
		}
		if (StringUtils.equals(entity.getFlag(), "1")) {
			return Constants.DONE;
		}
		return Constants.OWN;
	}

	public void prepareJudge() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 接收任务 taketask: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String taketask() throws Exception {
		HistoryProject historyProject = historyProjectManager.get(taskid);
		String activityName = conveyaManager.getTask(taskid).getActivityName();
		if (historyProject == null) {
			historyProject = new HistoryProject();
			historyProject.setKey(id);
			historyProject.setUserName(user.getUserName());
			historyProject.setStatus("000" + status);
			historyProject.setStartDate(new Date());
			historyProject.setTaskId(taskid);
			historyProject.setActivityName(activityName);
		}
		try {
			conveyaManager.takeTask(taskid, id, user, historyProject);
		} catch (org.jbpm.api.JbpmException e) {
			historyProjectManager.save(historyProject);
		}
		ControlHelpUtil.setObjectToSession("taskid", taskid);
		if (StringUtils.equals(activityName, "拟办意见")) {
			return "part1";
		} else if (StringUtils.equals(activityName, "部门负责人审核")) {
			return "part2";
		} else if (StringUtils.equals(activityName, "部门会签")) {
			return "part3";
		} else if (StringUtils.equals(activityName, "分管领导审核")) {
			return "part4";
		} else if (StringUtils.equals(activityName, "站长签发")) {
			return "part5";
		} else if (StringUtils.equals(activityName, "综合室发文")) {
			return "part6";
		} else if (StringUtils.equals(activityName, "归档")) {
			return "part7";
		} else if (StringUtils.equals(activityName, "综合室审核")) {
			return "part8";
		} else if (StringUtils.equals(activityName, "拟稿人查看")) {
			return "part9";
		} else if (StringUtils.equals(activityName, "发文")) {
			return "part10";
		} else if (StringUtils.equals(activityName, "部门负责人处理")) {
			return "part11";
		}
		return null;
	}

	public void prepareTaketask() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	protected void prepareModel() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

	/**
	 * 下载word文档 word: 适用:
	 * 
	 * @return
	 * @throws Exception
	 * @exception
	 * @since 1.0.0
	 */
	public String word() throws Exception {
		return Constants.WORD;
	}

	public void prepareWord() throws Exception {
		if (StringUtils.isNotEmpty(id)) {
			entity = conveyaManager.get(id);
		} else {
			entity = new Convey();
		}
	}

}
